from pymongo import DESCENDING
from utilsapp import utils
from flask import Blueprint, current_app, request
from utilsapp.mysql_con import  db_pagelist,db_delete,db_connect
from utilsapp.common import assign_value, parsing_data_id

bluePrint = Blueprint('lubrication', __name__)

@bluePrint.route('/get', methods=["post"])
def get():
    proj_no = '0026'
    mgdb = current_app.mgdb[f'ieplat_{proj_no}']
    collection = mgdb[f"eige"]
    pipeline = [
    {
        "$match": {
            "_id": {"$regex": request.json['port'] + '_' + request.json['address']}
        }
    },
    {
        "$sort": {
            "_id": DESCENDING
        }
    },
    {
        "$limit": 1
    }
    ]

    result = list(collection.aggregate(pipeline))
    # 打印查询结果
    data = result[0]['data']
 
    return utils.ok(data)